package service

import "yanxue_ai_go/pkg/common/ai"

// ChatServiceRequest AI聊天服务请求
type ChatServiceRequest struct {
	Messages         []ChatServiceMessage       `json:"messages"`
	ModelID          string                     `json:"model_id,omitempty"`
	Provider         string                     `json:"provider,omitempty"`
	Temperature      *float32                   `json:"temperature,omitempty"`
	MaxTokens        *int                       `json:"max_tokens,omitempty"`
	TopP             *float32                   `json:"top_p,omitempty"`
	FrequencyPenalty *float32                   `json:"frequency_penalty,omitempty"`
	PresencePenalty  *float32                   `json:"presence_penalty,omitempty"`
	Stop             []string                   `json:"stop,omitempty"`
	Stream           bool                       `json:"stream,omitempty"`
	Tools            []ToolService              `json:"tools,omitempty"`
	ToolChoice       interface{}                `json:"tool_choice,omitempty"`
	Metadata         map[string]interface{}     `json:"metadata,omitempty"`
	Criteria         *ai.ModelSelectionCriteria `json:"criteria,omitempty"`
}

// ChatServiceResponse AI聊天服务响应
type ChatServiceResponse struct {
	ID                string          `json:"id"`
	Object            string          `json:"object"`
	Created           int64           `json:"created"`
	Model             string          `json:"model"`
	Provider          string          `json:"provider"`
	Choices           []ChoiceService `json:"choices"`
	Usage             UsageService    `json:"usage"`
	SystemFingerprint string          `json:"system_fingerprint,omitempty"`
}

// ChatServiceMessage 聊天消息
type ChatServiceMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

// ChoiceService 选择
type ChoiceService struct {
	Index        int                 `json:"index"`
	Message      ChatServiceMessage  `json:"message"`
	Delta        *ChatServiceMessage `json:"delta,omitempty"`
	FinishReason string              `json:"finish_reason"`
}

// UsageService 使用统计
type UsageService struct {
	PromptTokens     int `json:"prompt_tokens"`
	CompletionTokens int `json:"completion_tokens"`
	TotalTokens      int `json:"total_tokens"`
}

// ToolService 工具
type ToolService struct {
	Type     string          `json:"type"`
	Function FunctionService `json:"function"`
}

// FunctionService 函数
type FunctionService struct {
	Name        string      `json:"name"`
	Description string      `json:"description"`
	Parameters  interface{} `json:"parameters"`
}

// ModelServiceInfo 模型服务信息
type ModelServiceInfo struct {
	ID          string   `json:"id"`
	Provider    string   `json:"provider"`
	Type        string   `json:"type"`
	Name        string   `json:"name"`
	Description string   `json:"description"`
	MaxTokens   int      `json:"max_tokens"`
	InputPrice  float64  `json:"input_price"`
	OutputPrice float64  `json:"output_price"`
	Features    []string `json:"features"`
}

// ModelSwitchRequest 模型切换请求
type ModelSwitchRequest struct {
	ModelID string                 `json:"model_id" binding:"required"`
	Config  map[string]interface{} `json:"config,omitempty"`
}

// ModelAddRequest 模型添加请求
type ModelAddRequest struct {
	Provider  string                 `json:"provider" binding:"required"`
	ModelName string                 `json:"model_name" binding:"required"`
	Config    map[string]interface{} `json:"config,omitempty"`
}

// ModelHealthResponse 模型健康状态响应
type ModelHealthResponse struct {
	ModelID   string `json:"model_id"`
	Healthy   bool   `json:"healthy"`
	Error     string `json:"error,omitempty"`
	CheckedAt int64  `json:"checked_at"`
}
